﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace bookshop
{
    public partial class DashBoard : Form
    {
        public DashBoard()
        {
            InitializeComponent();
        }

        SqlConnection Con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\C#\MyProject\BookShopDb.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=False;");

        private void label9_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void DashBoard_Load(object sender, EventArgs e)
        {
            foreach (Control c in panel3.Controls)
            {
                c.MouseClick += (s, e2) => panel3_MouseClick(panel3, e2);
            }
            foreach (Control c in panel6.Controls)
            {
                c.MouseClick += (s, e2) => panel6_MouseClick(panel6, e2);
            }
            foreach (Control c in panel5.Controls)
            {
                c.MouseClick += (s, e2) => panel5_MouseClick(panel5, e2);
            }

            Con.Open();
            string query = "select sum(BQty) from BookTb1";
            SqlDataAdapter scd = new SqlDataAdapter(query, Con);
            DataTable dt = new DataTable();
            scd.Fill(dt);
            BookStockLbl.Text = dt.Rows[0][0].ToString();

            string query2 = "select sum(Amount) from BillTb1";
            SqlDataAdapter scd2 = new SqlDataAdapter(query2, Con);
            DataTable dt2 = new DataTable();
            scd2.Fill(dt2);
            AmountLbl.Text = dt2.Rows[0][0].ToString(); 

            string query3 = "select count(*) from UserTb1";
            SqlDataAdapter scd3 = new SqlDataAdapter(query3, Con);
            DataTable dt3 = new DataTable();
            scd3.Fill(dt3);
            UserTotalLbl.Text = dt3.Rows[0][0].ToString();

            Con.Close();

        }

        private void panel3_MouseClick(object sender, MouseEventArgs e)
        {
            this.Hide();
            Books obj = new Books();
            obj.Show();
        }

        private void panel6_MouseClick(object sender, MouseEventArgs e)
        {
            this.Hide();
            User obj = new User();
            obj.Show();
        }

        private void panel5_MouseClick(object sender, MouseEventArgs e)
        {
            this.Hide();
            login obj = new login();
            obj.Show();
        }
    }
}
